#include "../../core/src/log.h"
#include "eventqueue.h"

EventQueue::EventQueue()
{

}

EventQueue::~EventQueue()
{

}

void EventQueue::postEvent(const EventPtr &ev)
{
    Mutex::scoped_lock lock(m_lock);

    m_queue.push_back(ev);
    m_waiter.notify_one();
}

void EventQueue::peekEvent(EventPtr &ev)
{
    Mutex::scoped_lock lock(m_lock);

    while(m_queue.empty()){
        LOG_TRACE() << "Wait event...";
        m_waiter.wait(m_lock);
    }

    ev = m_queue.front();
    m_queue.pop_front();
}

size_t EventQueue::size()
{
    Mutex::scoped_lock lock(m_lock);

    return m_queue.size();
}
